<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/1/29
 * Time: 11:27
 */

namespace App;


use Illuminate\Database\Eloquent\Model;

class CashCoupon extends Model
{
    // 表名称
    protected $table = 'cash_coupon';
    // 开启自动时间戳
    public $timestamps = true;
    // 日期都存储为时间戳
    protected $dateFormat = 'U';

    // 时间类型字段
    protected $dates = [
        'created_at',
        'updated_at',
        'deleted_at',
        'start_time',
        'end_time'
    ];

    // 将钱数改变面额单位从元换算成分
    public function setDenominationAttribute($value)
    {
        $this->attributes['denomination'] = $value*100;
    }
    // 将钱数改变面额单位从分换算成元
    public function getDenominationAttribute($value)
    {
        return $value/100;
    }

    // 将钱数改变费用最低限度单位从元换算成分
    public function setLimitAttribute($value)
    {
        $this->attributes['limit'] = $value*100;
    }
    // 将钱数改变费用最低限单位从分换算成元
    public function getLimitAttribute($value)
    {
        return $value/100;
    }

    // 将代金券有效期开始时间转换成时间戳
    public function setStartTimeAttribute($value)
    {
        $this->attributes['start_time'] = strtotime($value);
    }
    // 将代金券有效期结束时间转换成时间戳
    public function setEndTimeAttribute($value)
    {
        $this->attributes['end_time'] = strtotime($value);
    }
}